<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.cyt.${module?replace('/','.')}.dao.${entity}Dao">

    <select id="selectByCondition" parameterType="${entity}Vo" resultType="${entity}Vo">
        select t.*
<#if (relateInfo?? && relateInfo !='')>
    <#list relateInfo?split(";") as search>
        ,${search?split(":")[2]}.${search?split(":")[5]} ${search?split(":")[0]}${search?split(":")[6]}
    </#list>
</#if>
        from ${tableName} t
<#if (relateInfo?? && relateInfo !='')>
    <#list relateInfo?split(";") as search>
        <#if search_index == 0>
        left join ${search?split(":")[3]} ${search?split(":")[2]} on t.${search?split(":")[7]} = ${search?split(":")[2]}.${search?split(":")[4]}
        <#else>
            <#list relateInfo?split(";") as s>
                <#if s_index < search_index>
                    <#if search?split(":")[3] == s?split(":")[3]>
                        <#if search?split(":")[2] != s?split(":")[2]>
                        and t.${search?split(":")[7]} = ${search?split(":")[2]}
                        </#if>
                    <#else>
                        <#if s_index == search_index - 1>
                    left join ${search?split(":")[3]} ${search?split(":")[2]} on t.${search?split(":")[7]} = ${search?split(":")[2]}.${search?split(":")[4]}
                        </#if>
                    </#if>
                </#if>
            </#list>
        </#if>
    </#list>
</#if>
        where t.remove_tag = '1'
        <if test="id != null and id != ''">
            and t.id = ${r'#{id}'}
        </if>
    <#if (searchNotRelate?? && searchNotRelate !='')>
        <#list searchNotRelate?split(";") as search>
            <#if search?split(":")[2] == 'input'>
        <if test="${search?split(":")[1]} != null and ${search?split(":")[1]} != ''">
            and t.${search?split(":")[0]} like '%${r'${'}${search?split(":")[1]}}%'
        </if>
            <#elseif search?split(":")[2] == 'dateTime'>
        <if test="${search?split(":")[1]} != null and ${search?split(":")[1]} != ''">
            <#if search?split(":")[4] == 'year'>
            and DATE_FORMAT(t.${search?split(":")[0]},"%Y") = ${r'#{'}${search?split(":")[1]}}
            <#elseif search?split(":")[4] == 'month'>
            and DATE_FORMAT(t.${search?split(":")[0]},"%Y-%m") = ${r'#{'}${search?split(":")[1]}}
            <#elseif search?split(":")[4] == 'date'>
            and DATE_FORMAT(t.${search?split(":")[0]},"%Y-%m-%d") = ${r'#{'}${search?split(":")[1]}}
            <#elseif search?split(":")[4] == 'time'>
            and DATE_FORMAT(t.${search?split(":")[0]},"%H:%i:%s") = ${r'#{'}${search?split(":")[1]}}
            <#elseif search?split(":")[4] == 'datetime'>
            and DATE_FORMAT(t.${search?split(":")[0]},"%Y-%m-%d %H:%i:%s") = ${r'#{'}${search?split(":")[1]}}
            </#if>
        </if>
            <#else>
        <if test="${search?split(":")[1]} != null and ${search?split(":")[1]} != ''">
            and t.${search?split(":")[0]} = ${r'#{'}${search?split(":")[1]}}
        </if>
            </#if>
        </#list>
    </#if>
    </select>

</mapper>